package leetcode;

/**
 * @program: javase
 * @description:
 * @author: hmx
 * @create: 2021-10-09 23:01
 **/
public class LeetCode27 {
    /*public int removeElement(int[] nums, int val) {
        int len = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                len = i + 1;
                continue;
            }
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[j] != val) {
                    nums[i] = nums[j];
                    nums[j] = val;
                    i--;
                    break;
                }
            }
        }
        return len;
    }*/
    public int removeElement(int[] nums, int val) {
        int left = 0;
        for (int right = 0; right < nums.length; right++) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                left++;
            }
        }
        return left;
    }

}
